package com.zsummer.zero.thread;

/**
 * �ж��߳�
 *  stop������̫��³���Ѿ������� 
 * interrupt:���÷����ж��̣߳����ô˷����������ж��̣߳�ֻ�ǻ��һ���жϱ�ǣ�
 * interrupted()��isinterrupted���������𣺵�һ�������interrupted״̬���ڶ����������interrupted״̬
 * 
 * @author zhouyujiang
 *
 */
public class ThreadDemo1 {

	/*
	 * public static void main(String[] args) { Thread myThread = new Thread(() -> {
	 * System.out.println(Thread.currentThread().getName());
	 * System.out.println(Thread.currentThread().isInterrupted());
	 * 
	 * Thread.currentThread().interrupt();
	 * System.out.println(Thread.currentThread().getName());
	 * System.out.println(Thread.currentThread().isInterrupted());
	 * 
	 * // try { // Thread.sleep(1000); //// Thread.currentThread().wait(); ////
	 * Thread.currentThread().join(); // System.out.println("zzzzzzzzzzzz"); // }
	 * catch (InterruptedException e) { //
	 * System.out.println(Thread.currentThread().getName()); //
	 * System.out.println("******"+Thread.currentThread().isInterrupted()); //
	 * e.printStackTrace(); // }
	 * System.out.println(Thread.currentThread().getName()); }); myThread.start();
	 * try { Thread.currentThread().sleep(1000); System.out.println(100000); } catch
	 * (InterruptedException e) { // TODO Auto-generated catch block
	 * e.printStackTrace(); } }
	 */

	/*
	 * public static void main(String[] args) { Thread myThread = new Thread(() -> {
	 * System.out.println(Thread.currentThread().getName()); try {
	 * Thread.currentThread().sleep(10000); } catch (InterruptedException e) {
	 * boolean interrupted = Thread.currentThread().isInterrupted();
	 * System.out.println(interrupted); e.printStackTrace(); } }); myThread.start();
	 * try { Thread.currentThread().sleep(5000); } catch (InterruptedException e) {
	 * // TODO Auto-generated catch block e.printStackTrace(); }
	 * System.out.println("5 second later"); myThread.interrupt();
	 * System.out.println(myThread.isInterrupted()); System.out.println("end"); }
	 */

	/**
	 * ��ȷ������1
	 * 
	 * @param args
	 */
/*	 public static void main(String[] args) {
	 Thread thread = new Thread(()-> {
	 try {
	 while(true) {
	 if (Thread.interrupted()) {
	 System.out.println("you will be interrupted!");
	 throw new InterruptedException();
	 }
	 System.out.println("i am running!");
	 }
	
	 } catch (InterruptedException e) {
	 System.out.println("i am interrupted");
	 }
	 }) ;
	
	 thread.start();
	 try {
	 Thread.sleep(10000);
	 } catch (InterruptedException e) {
	 e.printStackTrace();
	 }
	 thread.interrupt();
	
	 }*/
	/**
	 * ��ȷ������2
	 * 
	 * @param args
	 */
/*	public static void main(String[] args) {
		Thread thread = new Thread(() -> {
			try {
				while (true) {
					System.out.println("i am running!");
					Thread.sleep(1);
				}
			} catch (InterruptedException e) {
				System.out.println("i am interrupted!");
			}

		});

		thread.start();
		try {
			Thread.sleep(10000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		thread.interrupt();

	}*/
	
	/**
	 * ������stop����
	 */
/*	public static void main(String[] args) {
		Thread thread = new Thread(() -> {
			while (true) {
				System.out.println("i am running!");
			}
		});
	
		thread.start();
		try {
			Thread.sleep(10000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		thread.stop();
	}*/
}
